package com.bw.zg2.view.activity

import android.os.Bundle
import android.os.CountDownTimer
import com.alibaba.android.arouter.launcher.ARouter
import com.bw.zg2.R
import com.bw.zg2.base.BaseActivity
import com.bw.zg2.databinding.ActivityWelcomeBinding
import com.bw.zg2.viewmodel.HomeViewModel

class WelcomeActivity :
    BaseActivity<HomeViewModel, ActivityWelcomeBinding>(R.layout.activity_welcome) {

    private lateinit var countDownTimer: CountDownTimer

    override fun initView(savedInstanceState: Bundle?) {
        //给倒计时赋值
        countDownTimer = object : CountDownTimer(3000, 1000) {
            override fun onTick(p0: Long) {
                dataBinding.tvTime.text = "${(p0+1000) / 1000}秒后跳转"
            }

            override fun onFinish() {
                //跳转页面
                //如果未登录，则通过登录拦截器，跳转到登录页面，如果已经登录，则直接进入主页面
                ARouter.getInstance()
                    .build("/main/MainActivity")
                    // 如果有拦截器，则会执行拦截器的代码逻辑
                    .withString("name","zs")
                    .withInt("age",23)
                    .navigation()
                countDownTimer.cancel()
                finish()
            }
        }
        //开启倒计时
        countDownTimer.start()
    }

    override fun onDestroy() {
        super.onDestroy()
        //防止页面内存泄漏
        countDownTimer.cancel()
    }

    override fun initData() {
    }


}